﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace TeF.Runner.Extensions
{
    internal static class AssemblyExtensions
    {
        public static IEnumerable<Type> GetTestTypes<TAttribute>(this Assembly assembly)
            where TAttribute : Attribute
        {
            if (assembly == null)
                throw new ArgumentNullException("assembly");

            return
                assembly.GetTypes()
                    .Where(t =>
                           t.IsPublic &&
                           t.IsClass &&
                           !t.IsAbstract &&
                           !t.IsInterface &&
                           t.IsVisible &&
                           t.HasAttribute<TAttribute>());
        }
    }
}
